package com.copa.l2299;

import java.util.HashSet;
import java.util.Set;

/**
 * @author copa
 * @createDate 2023-01-19 17:18
 * @function 常规法
 */
public class Test1 {

    public boolean strongPasswordCheckerII(String password) {
        if (password.length() < 8) {
            return false;
        }
        boolean lowerFlag = false;
        boolean upperFlag = false;
        boolean numFlag = false;
        boolean otherFlag = false;
        Set<Character> otherSet = new HashSet<>();
        //!@#$%^&*()-+
        otherSet.add('!');
        otherSet.add('@');
        otherSet.add('#');
        otherSet.add('$');
        otherSet.add('%');
        otherSet.add('^');
        otherSet.add('&');
        otherSet.add('*');
        otherSet.add('(');
        otherSet.add(')');
        otherSet.add('-');
        otherSet.add('+');
        char[] passwordArray = password.toCharArray();
        for (int i = 0; i < passwordArray.length; i++) {
            char c = passwordArray[i];
            if (i < passwordArray.length - 1 && c == passwordArray[i + 1]) {
                return false;
            }
            if (!lowerFlag && c >= 'a' && c <= 'z') {
                lowerFlag = true;
                continue;
            }
            if (!upperFlag && c >= 'A' && c <= 'Z') {
                upperFlag = true;
                continue;
            }
            if (!numFlag && c >= '0' && c <= '9') {
                numFlag = true;
                continue;
            }
            if (!otherFlag && otherSet.contains(c)) {
                otherFlag = true;
            }
        }
        return lowerFlag && upperFlag && numFlag && otherFlag;
    }

    public static void main(String[] args) {
        //String password = "IloveLe3tcode!";
        String password = "aA0!bB1@@3rbHkB8Puvl";
        System.out.println(new Test1().strongPasswordCheckerII(password));
    }
}
